﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyThuoc.DAL
{
   public class NhaCCDAL:KetNoiDAL
    {
       public DataTable SelectAll_NhaCC()
       {
           SqlCommand cmd = new SqlCommand("SelectAll_NhaCC", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable LayMaNCCTheoTen()
       {
           SqlCommand cmd = new SqlCommand("LayMaNCCTheoTen", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable LayNhaCCTheoMa()
       {
           SqlCommand cmd = new SqlCommand("LayNhaCCTheoMa", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable Search(int MaNCC, string TenNCC, string DiaChi, string SoDT, string Email)
       {
           SqlCommand cmd = new SqlCommand("Search_NCC", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDNCC", MaNCC);
           cmd.Parameters.AddWithValue("@TenNCC", TenNCC);
           cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
           cmd.Parameters.AddWithValue("@Email", Email);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SearchNhaCC_Condition(string keyword)
       {
           SqlCommand cmd = new SqlCommand("SearchNhaCC_Condition", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@keyword", keyword);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SelectID_NhaCC(int MaNCC)
       {
           SqlCommand cmd = new SqlCommand("Search_NCC", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDNCC", MaNCC);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }

       public DataTable SearchDK(int MaNCC, string TenNCC, string DiaChi, string SoDT, string Email)
       {
           SqlCommand cmd = new SqlCommand("SearchNhaCCByCondition", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDNCC", MaNCC);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@TenNCC", TenNCC);
           cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
           cmd.Parameters.AddWithValue("@SoDT", SoDT);
           cmd.Parameters.AddWithValue("@Email", Email);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
           
       }
       public int InsertNhaCC(string TenNCC, string DiaChi, string SoDT, string Email)
       {
           //try
           //{
               SqlCommand cmd = new SqlCommand("Insert_NhaCC", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@TenNCC", TenNCC);
               cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
               cmd.Parameters.AddWithValue("@SoDT", SoDT);
               cmd.Parameters.AddWithValue("@Email", Email);
             return  cmd.ExecuteNonQuery();
               //return true;
           //}
           //catch (Exception)
           //{
           //    //return false;
           //}
       }
       public int UpdateNhaCC(int MaNCC, string TenNCC, string DiaChi, string SoDT, string Email)
       {
          
               SqlCommand cmd = new SqlCommand("Update_NhaCC", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDNCC", MaNCC);
               cmd.Parameters.AddWithValue("@TenNCC", TenNCC);
               cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
               cmd.Parameters.AddWithValue("@SoDT", SoDT);
               cmd.Parameters.AddWithValue("@Email", Email);
              return cmd.ExecuteNonQuery();
          
       }
       public int DeleteNhCC(int MaNCC)
       {

               SqlCommand cmd = new SqlCommand("Delete_NhaCC", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDNCC", MaNCC);
             return  cmd.ExecuteNonQuery();
            
       }
    }
}
